//
//  PhoneRecordCell.swift
//  DiZhenYuJing
//
//  Created by zhibao on 2024/12/22.
//

class PhoneRecordCell: UITableViewCell {
    fileprivate var nameLabel = UILabel()
    fileprivate var durationLabel = UILabel()
    fileprivate var createTimeLabel = UILabel()
    fileprivate var audioImgView = UIImageView(image: UIImage(systemName: "waveform"))
    fileprivate var selectBtn:UIButton!
    @objc var doneBlock:RightDoneBlock?
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        self.backgroundColor = UIColor.clear
        self.contentView.backgroundColor = UIColor.clear
        let bgView = UIView()
        bgView.backgroundColor = MYColor.color(withHexString: "#f2f2f2", alpha: 0.8)
        self.contentView.addSubview(bgView)
        bgView.layer.cornerRadius = pixw(p:15)
        bgView.snp.makeConstraints { make in
            make.left.equalTo(pixw(p:15))
            make.top.equalTo(pixw(p:10))
            make.right.equalTo(pixw(p:-15))
//            make.height.equalTo(pixw(p:70))
            make.bottom.equalTo(0)
        }
        
        audioImgView.tintColor = MYRed
        bgView.addSubview(audioImgView)
        audioImgView.snp.makeConstraints { make in
            make.left.equalTo(pixw(p:15))
            make.centerY.equalTo(bgView)
        }
        
        selectBtn = UIButton(type: .custom)
        selectBtn.setImage(UIImage(systemName: "square.and.arrow.up.fill"), for: .normal)
        selectBtn.tintColor = MYBlue
        selectBtn.addTarget(self, action: #selector(selectBtnCilck), for: .touchUpInside)
        bgView.addSubview(selectBtn)
        selectBtn.snp.makeConstraints { make in
            make.right.equalTo(pixw(p:-15));
            make.centerY.equalTo(bgView);
            make.width.height.equalTo(pixw(p:40));
        }
        
        nameLabel.text = "20241110_audio.mp3"
        nameLabel.font = MY_SCALE_FONT(13)
        nameLabel.textColor = MYBlock
        bgView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(pixw(p:55))
            make.top.equalTo(pixw(p:10))
            //make.right.equalTo(selectBtn.snp.left).offset(pixw(p:-15))
        }
        
        durationLabel.text = "时长:100s"
        durationLabel.font = MY_SCALE_LightFONT(11)
        durationLabel.textColor = MYColor.color(withHexString: "999999")
        bgView.addSubview(durationLabel)
        durationLabel.snp.makeConstraints { make in
            make.left.equalTo(nameLabel.snp.right).offset(pixw(p: 3))
            make.centerY.equalTo(nameLabel)
        }
        
        createTimeLabel.text = "2024-10-32 19:33:33"
        createTimeLabel.font = MY_SCALE_FONT(11)
        createTimeLabel.textColor = MYColor.color(withHexString: "666666")
        bgView.addSubview(createTimeLabel)
        createTimeLabel.snp.makeConstraints { make in
            make.left.right.equalTo(nameLabel)
            make.top.equalTo(nameLabel.snp.bottom).offset(pixw(p:4))
            make.bottom.equalTo(bgView).offset(pixw(p:-10))
        }
    }
    
    // 0 显示分享  1显示文件夹
    func updata(dic:[String:Any],selectType:NSString = "0"){
        selectBtn.isHidden = false
        selectBtn.setImage(UIImage(systemName: "square.and.arrow.up.fill"), for: .normal)
        nameLabel.text = dic["title"] as? String
        //时长
        
        createTimeLabel.text = dic["startTime"] as? String
        durationLabel.text = "时长:\(String(describing: dic["duration"]!))s"
    }

    @objc func selectBtnCilck(){
        if((self.doneBlock) != nil){
            self.doneBlock!()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
